package cn.wbnyua.resume.api.api2;

import cn.wbnyua.resume.core.exception.RuntimeExceptionHandler;
import cn.wbnyua.resume.mvc.domain.Skills;
import cn.wbnyua.resume.mvc.service.v2.SkillsService;
import cn.wbnyua.resume.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：wbnyua.
 * 创建时间: 2023/2/7 14:05.
 */

@RestController
@RequestMapping("/api/skills")
public class SkillApi {


    @Autowired
    private SkillsService service;

    @GetMapping
    public JsonResponse<List<Skills>> list(){
        return new JsonResponse<>(service.findAll());
    }

    @PostMapping
    public JsonResponse<String> add(Skills skills){
        service.add(skills);
        return JsonResponse.success();
    }

    @PutMapping
    public JsonResponse<String> update(Skills skills){
        if (skills.getId()==null){
            throw new RuntimeExceptionHandler("用户数据有误");
        }
        service.update(skills);
        return JsonResponse.success();
    }


    @DeleteMapping("/{id}")
    public JsonResponse<String> remove(@PathVariable Long id){
        if (id==null){
            throw new RuntimeExceptionHandler("请输入删除的编号");
        }
        service.remove(id);
        return JsonResponse.success();
    }

}
